#ifndef __PCAN_COMMON_H__
#define __PCAN_COMMON_H__

//****************************************************************************
// Copyright (C) 2001-2004  PEAK System-Technik GmbH
//
// linux@peak-system.com
// www.peak-system.com
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// Maintainer(s): Klaus Hitschler (klaus.hitschler@gmx.de)
//****************************************************************************

//****************************************************************************
//
// global defines to include in all files this module is made of
// ! this must always the 1st include in all files !
//
// $Log: pcan_common.h,v $
// Revision 1.33  2005/02/12 14:24:16  klaus
// bug removed when CAN_ERR_QXMTFULL was raised even when no queue was filled
//
// Revision 1.32  2005/01/30 21:33:42  klaus
// added simple error message when usb-dongle returns CAN_ERR_QXMTFULL
//
// Revision 1.31  2004/12/16 21:00:36  klaus
// experimental "... context at in_atomic() ..." bug fix, release_20041216
//
// Revision 1.30  2004/12/09 21:23:56  klaus
// serial number + HW-Revision 28 bug fixed
//
// Revision 1.29  2004/11/30 19:33:05  klaus
// release_20041130, timeout in urb_t removed up from kernel 2.6.8, ready for SuSE-9.2
//
// Revision 1.28  2004/11/21 20:33:04  klaus
// test release to get serial number bug
//
// Revision 1.27  2004/10/24 21:17:33  klaus
// release_20041024, timeout in urb_t removed up from kernel 2.6.9
//
// Revision 1.26  2004/09/14 17:57:40  klaus
// Released release_20040915_x
//
// Revision 1.25  2004/07/18 14:15:54  klaus
// removed 'scheduling while atomic!', accept or transmitt DLC while ignoring data content when RTR data
//
// Revision 1.24  2004/05/13 15:38:35  klaus
// Release of 20040513
//
// Revision 1.23  2004/05/13 15:32:58  klaus
// devfs is depreciated, moved handling from Makefile to pcan_common.h
//
// Revision 1.22  2004/05/06 19:08:13  klaus
// Improvements triggered by Mandrake distribution 2.6.3-7mdk: MODULE_VERSION macro
//
// Revision 1.21  2004/05/06 18:48:10  klaus
// Improvements triggered by Mandrake distribution 2.6.3-7mdk: MODULE_VERSION macro
//
// Revision 1.20  2004/05/02 15:56:51  klaus
// Last corrections and improvements, especially for Makefile(s) and build scenarios
//
// Revision 1.19  2004/05/02 12:53:21  klaus
// try to get source compatibility between kernels 2.6.x and 2.4.x
//
// Revision 1.18  2004/04/18 17:59:13  klaus
// added MODULE_VERSION support for kernel 2.6.x
//
// Revision 1.17  2004/04/13 19:43:35  klaus
// release_20040413_x; improved timestamp calculation for USB
//
// Revision 1.16  2004/04/11 22:03:29  klaus
// cosmetic changes
//
// Revision 1.15  2004/04/10 12:25:39  klaus
// merge polished between HEAD and kernel-2.6 branch
//
// Revision 1.14  2004/04/10 08:57:26  klaus
// merge finished between HEAD and kernel-2.6 branch
//
//****************************************************************************

//****************************************************************************
// DEFINES
#ifndef __KERNEL__
  #define __KERNEL__
#endif
#ifndef MODULE
  #define MODULE
#endif

#include <linux/version.h>  // if this file is not found: please look @ /boot/vmlinuz.version.h and make a symlink

// support for MODVERSIONS
#include <linux/autoconf.h>
#if defined(CONFIG_MODVERSIONS) && !defined(MODVERSIONS)
  #define MODVERSIONS
#endif

#ifdef MODVERSIONS
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    #include <config/modversions.h>
  #else
    #include <linux/modversions.h>
  #endif
#endif

// support for DEVFS - not for kernels >= 2.6
#if (!defined(CONFIG_DEVFS_FS) && !defined(DEVFS_SUPPORT)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
  #undef DEVFS_SUPPORT
#endif

// support for PARPORT_SUBSYSTEM
#if !defined(CONFIG_PARPORT_MODULE) && !defined(CONFIG_PARPORT) && defined(PARPORT_SUBSYSTEM)
  #undef PARPORT_SUBSYSTEM
#endif

// support for USB
#if !defined(CONFIG_USB_MODULE) && !defined(CONFIG_USB) && defined(USB_SUPPORT)
  #undef USB_SUPPORT
#endif


// support only versions 2.2.x and 2.4.x
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,0)
  #error "This kernel is too old and not supported"
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
  #define LINUX_22 // LINUX 2.2.x
#else
  #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
    #define LINUX_24 // >= LINUX 2.4.x && < LINUX 2.6
  #else
    #define LINUX_26 // >= LINUX 2.6
  #endif
#endif

// there were some changes during 2.2.x
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
  #define DECLARE_WAIT_QUEUE_HEAD(head) struct wait_queue *head = NULL
  typedef  struct wait_queue *wait_queue_head_t;
  #define init_waitqueue_head(head) (*(head)) = NULL
  #define list_add_tail(x, y) __list_add(x, (y)->prev, y)
#endif

// some preparative defintions for kernel 2.6.x 
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,24)
  typedef void irqreturn_t;
  #define IRQ_NONE
  #define IRQ_HANDLED
  #define IRQ_RETVAL(x)
#endif

// switch to disable all printks for not debugging
#ifdef DEBUG
  #define DPRINTK printk
#else
  #define DPRINTK(stuff...)
#endif


//----------------------------------------------------------------------------
// set here the current release of the driver 'Release_date_nr' synchronoes
// with CVS until we have managed that CVS does it itself
#ifdef USB_SUPPORT
#define CURRENT_RELEASE "release_20050212_u"  // $name$
#else
#define CURRENT_RELEASE "release_20050212_a"  // $name$
#endif

#endif // __PCAN_COMMON_H__
